package cn.gson.springboot.controller.aftercontroller;

import cn.gson.springboot.model.pjos.Dept;
import cn.gson.springboot.model.pjos.Expense;
import cn.gson.springboot.model.service.afterservice.ExpenseService;
import cn.gson.springboot.model.vo.aftervo.ExpenseVo;
import cn.gson.springboot.model.vo.aftervo.MaintainChartVo;
import cn.gson.springboot.model.vo.aftervo.PieDoubleVo;
import com.github.pagehelper.Page;
import com.github.pagehelper.PageHelper;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Controller;
import org.springframework.web.bind.annotation.RequestBody;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.ResponseBody;

import java.util.HashMap;
import java.util.List;
import java.util.Map;

@Controller
@RequestMapping("/exs")
public class ExpenseController {

    @Autowired
    ExpenseService sc;

    @RequestMapping("/exps-page")
    @ResponseBody
    public Map<String,Object> expsPage(Integer employeesId,Integer fatherDeptId,String states, String search, Integer currPage, Integer pageSize){
        Page<Object> obj = PageHelper.startPage(currPage, pageSize);
        List<Expense> exps = sc.selectExpsPage(employeesId,fatherDeptId,states,search);

        Map<String,Object> map = new HashMap<>();
        map.put("rows",obj.getResult());        //分页后的数据，一页展示多少数据
        map.put("total",obj.getTotal());        //总条数
        return map;
    }

    @RequestMapping("/check-emp")
    @ResponseBody
    public List<Dept> checkEmp(){
        return sc.selectEmp();
    }

    @RequestMapping("/save-exps")
    @ResponseBody
    public void saveExps(@RequestBody ExpenseVo exps){
        sc.addExps(exps);
    }

    @RequestMapping("/update-exps")
    @ResponseBody
    public Expense updateExps(Integer expsId){
        return sc.selectExpsId(expsId);
    }

    @RequestMapping("/check-empId")
    @ResponseBody
    public String checkEmpId(Integer expsId){
        return sc.selectEmpId(expsId);
    }

    @RequestMapping("/emp-name")
    @ResponseBody
    public String empName(Integer employeesId){
        return sc.selectEmpName(employeesId);
    }

    @RequestMapping("/delete-exps")
    @ResponseBody
    public void deleteExps(Integer apprId,Integer expsId){
        sc.deleteByExpsId(apprId,expsId);
    }

    @RequestMapping("/exps-sort")
    @ResponseBody
    public List<MaintainChartVo> expsSort(Integer employeesId, Integer fatherDeptId){
        return sc.selectExpsBySort(employeesId, fatherDeptId);
    }

    @RequestMapping("/exps-money")
    @ResponseBody
    public List<PieDoubleVo> expsMoney(Integer employeesId, Integer fatherDeptId){
        return sc.selectExpsByMoney(employeesId, fatherDeptId);
    }

    @RequestMapping("/exps-month")
    @ResponseBody
    public List<String> expsMonth(Integer employeesId, Integer fatherDeptId){
        return sc.selectExpsByMonth(employeesId, fatherDeptId);
    }

    @RequestMapping("/month-money")
    @ResponseBody
    public List<Double> monthMoney(Integer employeesId, Integer fatherDeptId){
        return sc.selectMonthByMoney(employeesId, fatherDeptId);
    }

    @RequestMapping("/exps-custom")
    @ResponseBody
    public List<String> expsCustom(Integer employeesId, Integer fatherDeptId){
        return sc.selectExpsByCustom(employeesId, fatherDeptId);
    }

    @RequestMapping("/custom-sum")
    @ResponseBody
    public List<Double> customSum(Integer employeesId, Integer fatherDeptId){
        return sc.selectCustomBySum(employeesId, fatherDeptId);
    }

    @RequestMapping("/revoke-id")
    @ResponseBody
    public void revokeId(Integer apprId,Integer expsId,Integer empId){
        sc.revoke(apprId, expsId, empId);
    }

    @RequestMapping("/dispatch-id")
    @ResponseBody
    public void dispatchId(Integer expsId){
        sc.dispatch(expsId);
    }

    @RequestMapping("/postLevel-emp")
    @ResponseBody
    public List<Map<String, Object>> postLevelEmp(Integer employeesId){
        return sc.selectPostLevelEmp(employeesId);
    }

    @RequestMapping("/ordinary-two")
    @ResponseBody
    public Integer ordinaryTwo(Integer deptsId){
        return sc.selectOrdinaryByTwo(deptsId);
    }

    @RequestMapping("/ordinary-one")
    @ResponseBody
    public Integer ordinaryOne(Integer deptsId){
        return sc.selectOrdinaryByOne(deptsId);
    }

    @RequestMapping("/ordinary-boss")
    @ResponseBody
    public Integer ordinaryBoss(){
        return sc.selectOrdinaryByBoss();
    }
}
